package com.cnc.dao;

import com.cnc.pojo.Course;
import com.cnc.pojo.UserCourse;
import com.cnc.utils.PageUtil;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserCourseMapper {
    @Select("select id,c.uid,cid from course_user c left join user u on c.uid=u.uid where name like (concat('%',#{search},'%')) limit #{pu.off},#{pu.len}")
    List<UserCourse> getSelectList(@Param("pu")PageUtil pu,@Param("search") String search);

    @Select("select count(*) from course_user c left join user u on c.uid=u.uid where name like (concat('%',#{search},'%'))")
    int getCountRows(@Param("search") String search);

    @Delete("delete from course_user where id=#{id}")
    int delUserCourseById(@Param("id")int id);

    @Update("update course_user set cid=#{cid} where id=#{id}")
    int update(@Param("id") String id,@Param("cid") String cid);

    @Select("select count(*) from course_user where uid=#{uid} and cid=#{cid}")
    int haveBuy(@Param("uid")String uid, @Param("cid")String cid);

    @Insert("insert into course_user(uid,cid) values(#{uid},#{cid})")
    int add(@Param("uid")String uid, @Param("cid")String cid);

    @Select("select c.* from course_user u left join course c on u.cid=c.cid where uid=#{uid}")
    List<Course> getMyCourse(@Param("uid")String uid);
}
